package com.iteasy.manage.controller;

import org.iteasy.framework.commons.IdParam;
import org.iteasy.framework.commons.PageParam;
import org.iteasy.framework.commons.Result;
import com.iteasy.manage.entity.User;
import com.iteasy.manage.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * Created by bo.chen on 2020/04/22 16:39:24
 */
@RestController
@RequestMapping("user")
public class UserController {

    @Autowired
    private UserService userService;

    @GetMapping("page")
    public Page<User> page(PageParam pageParam) {
        Page<User> page = userService.page(pageParam);
        return page;
    }

    @GetMapping("get")
    public User get(@Validated IdParam idParam) {
        return userService.findById(idParam.getId());
    }

    @PostMapping("save")
    public Result<Object> save(@RequestBody @Validated User user) {
        userService.save(user);
        return Result.success();
    }

}
